import { $C, $rp } from '@/utils/constants';

const noteP = $C.notifications.position;

export default (note) => {
  const errs = ['评论提醒参数错误'];
  if (note.authorInfo.err) errs.push(note.authorInfo.msg);
  if (note.spaceInfo.err) errs.push(note.spaceInfo.msg);
  if (note.noteInfo.err) errs.push(note.noteInfo.msg);

  if (errs.length > 1) return { id: note.id, err: true, msg: errs.join(', ') };

  let [desc, rootPath] = [];
  const spacePath = `/${$rp.SPACES}/${note.spaceInfo.id}`;

  if (note.noteInfo.position === noteP.issue) {
    desc = '希望你参与讨论';
    rootPath = `${spacePath}/${$rp.SPACE_ISSUES}/${note.noteInfo.id}`;
  }

  return {
    type: note.type,
    author: note.authorInfo,
    desc,
    root: { title: note.noteInfo.title, path: rootPath },

    id: note.id,
    read: note.read,
    created_at: note.created_at,
    updated_at: note.updated_at,
  };
};
